package com.xu.cloud.common.pojo.http.resp;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.xu.cloud.common.exception.ErrorCodeEnum;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * http响应基础实体类
 *
 * @author xuguan
 * @since 2023/4/3
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class BaseResponse implements Serializable {
    private static final long serialVersionUID = 7556150892726608209L;
    /**
     * 响应码
     */
    private String code = ErrorCodeEnum.OK.getCode();
    /**
     * 响应信息
     */
    private String msg = ErrorCodeEnum.OK.getMessage();
    /**
     * 响应时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private final LocalDateTime respTime = LocalDateTime.now();
    /**
     * 扩展字段
     */
    private Map<String, Object> extra;

    public BaseResponse() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getExtra() {
        return extra;
    }

    public void setExtra(Map<String, Object> extra) {
        this.extra = extra;
    }

    public boolean isSuccess() {
        return ErrorCodeEnum.OK.getCode().equals(code);
    }
}
